package com.lzc.blog.admin.service.impl;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzc.blog.admin.mapper.CategoryMapper;
import com.lzc.blog.admin.mapper.TagMapper;
import com.lzc.blog.admin.model.params.PageParam;
import com.lzc.blog.admin.pojo.Category;
import com.lzc.blog.admin.pojo.Tag;
import com.lzc.blog.admin.service.CategoryService;
import com.lzc.blog.admin.service.TagService;
import com.lzc.blog.admin.vo.PageResult;
import com.lzc.blog.admin.vo.Result;
import com.mysql.cj.util.StringUtils;
import com.mysql.cj.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Result categoryList(PageParam pageParam) {
        IPage<Category> page = new Page<>();
        page.setCurrent(pageParam.getCurrentPage());
        page.setSize(pageParam.getPageSize());
        LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmptyOrWhitespaceOnly(pageParam.getQueryString())){
            queryWrapper.like(Category::getCategoryName,pageParam.getQueryString());
        }
        categoryMapper.selectPage(page, queryWrapper);
        PageResult<Category> pageResult = new PageResult<>(page.getRecords(),page.getTotal());
        return Result.success(pageResult);

    }
}
